import router from "@/router/index";
import { getToken } from "@/utils/token";
import type { RouteLocationNormalizedGeneric } from "vue-router";


const blackelist = ['/person','/serve/lost-found/lost-create','/serve/lost-found/found-create']
router.beforeEach((to, from, next) => {
    const hasetoken = getToken()
    // 条件1：已登录且访问登录页，跳转主页
    if (to.path === "/login" && hasetoken) {
        return next('/')
    }
    // 条件2：访问黑名单路径且未登录，跳转登录页
    if (blackelist.includes(to.path) && !hasetoken) { // 用includes更直观
        return next('/login')
    }
    return next()
})
